<?php

class BaiduLBS { 

    public static $_ak = 'S28IF6fq35DmhVy1UBuawAxBOPyjSOsc';//正式机:

         
    //获取经纬度坐标  
    public static function getLocation($data) {         
       if (!isset($data['address'])) {
           $info = $data;
           $url = 'http://api.map.baidu.com/geocoder/v2/';

           $info['ak'] = BaiduLBS::$_ak;
           $info['output'] = 'json';//输出格式

           $_log = new Logging();
           $_log->lfile('curl');
           $_log->lwrite("BaiduLBS::getLocation获取经纬度坐标:" . $url);
           $_log->lwrite(urldecode(json_encode($info)));

           $lbs_result = Util::request($url, 'POST', $info, false, 30);
           $_log->lwrite('result:' . $lbs_result);
           $_log->lwrite('....................................');
       }else {
           $address = $data['address'];
           $ak = BaiduLBS::$_ak;;
           $url = 'http://api.map.baidu.com/geocoder/v2/?address=' . $address . '&output=json&ak=' . $ak;

           $_log = new Logging();
           $_log->lfile('curl');
           $_log->lwrite("BaiduLBS::getLocation address:" . $address);
           $_log->lwrite("BaiduLBS::getLocation:" . $url);

           $lbs_result = Util::request($url, 'GET', '', false, 30);
           $_log->lwrite('result:' . $lbs_result);
           $_log->lwrite('....................................');
       }

        return $lbs_result;
         
    }

    //经纬度 转换
    public static function switchLocation($slng,$slat) {
        $ak = BaiduLBS::$_ak;;
        $url = 'http://api.map.baidu.com/geoconv/v1/?coords='.$slng.','.$slat.'&from=3&to=5&ak='. $ak;

        $_log = new Logging();
        $_log->lfile('baidu');
        $_log->lwrite("BaiduLBS::getLocation:" . $url);
        $location = Util::request($url, 'GET', '', false, 30);
        $_log->lwrite('result:' . $location);
        $_log->lwrite('....................................');

        return $location;

    }
     




    
}

?>
